import Vue from 'vue';
import App from './App';
import GoEasy from '@/uni_modules/GOEASY-IM/js_sdk/goeasy-2.13.8.esm.min.js'
import GRTC from './lib/goeasy-rtc-0.3.3.esm.min.js'

GoEasy.init({
	host: "hangzhou.goeasy.io", //应用所在的区域地址: 【hangzhou.goeasy.io |singapore.goeasy.io】
	appkey: "BC-dbb859b725654df298bf67957d3c042d", // common key
	modules: ['im'],
	// true表示支持通知栏提醒，false则表示不需要通知栏提醒
	allowNotification: true //仅有效于app,小程序和H5将会被自动忽略
});
GRTC.init(GoEasy);

uni.$GoEasy = GoEasy;
uni.$GRTC = GRTC;

GoEasy.onClickNotification((message) => {
	let currentUrl;
	const routes = getCurrentPages();

	if (routes && routes.length) {
		const curRoute = routes[routes.length - 1].route;
		const curParam = routes[routes.length - 1].options;
		currentUrl = '/' + curRoute + `?to=${curParam.to}`;
	}

	let newUrl;
	switch (message.toType) {
		case GoEasy.IM_SCENE.PRIVATE:
			newUrl = '/pages/privateChat?to=' + message.senderId;
			break;
		case GoEasy.IM_SCENE.GROUP:
			newUrl = '/pages/groupChat?to=' + message.groupId;
			break;
	}

	if (currentUrl !== newUrl) {
		uni.navigateTo({
			url: newUrl,
		});
	}

});

Vue.config.productionTip = false;
App.mpType = 'app';
const app = new Vue({
	...App
});
app.$mount();